﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; 
namespace CustomTask
{
     [Serializable]
     public class PrintKey : ProgramStatement
     {
          public static readonly DependencyProperty KeyProperty =
               DependencyProperty.Register("Key", typeof(PrintKey), typeof(string));
          public string Key
          {
               get { return (string)GetValue(KeyProperty); }
               set { SetValue(KeyProperty, value); }
          }

          public override ActivityExecutionStatus Run(BookmarkManager mgr)
          {
               // Print the key
               Key = DateTime.Now.Millisecond.ToString();
               Console.WriteLine("here is your key: " + Key);

               mgr.Done(false);
               return ActivityExecutionStatus.Closed;
          }
     }

    [Serializable]
    public class Read : ProgramStatement
    {
        //private string text;
        //public string Text
        //{
        //    get { return text; }
        //}
        public static readonly DependencyProperty TextProperty =
                    DependencyProperty.Register("Text", typeof(Read), typeof(string));
        public string Text
        {
             get { return (string)GetValue(TextProperty); }
             set { SetValue(TextProperty, value); }
        }
         
         public   override ActivityExecutionStatus Run(BookmarkManager mgr)
        {
            mgr.Add(new Bookmark("read", ContinueAt));
            return ActivityExecutionStatus.Closed;
        }

        void ContinueAt(Bookmark resumed)
        {
             Text = (string)resumed.Payload;

            BookmarkManager mgr = resumed.BookmarkManager;
            mgr.Remove(resumed);
            mgr.Done(false);
        }
    }
      
    [Serializable]
    public class PrintGreeting : ProgramStatement
    {
        public static readonly DependencyProperty KeyProperty =
            DependencyProperty.Register("Key", typeof(PrintGreeting), typeof(string));
        public static readonly DependencyProperty InputProperty =
            DependencyProperty.Register("Input", typeof(PrintGreeting), typeof(string));
        public string Key
        {
            get { return (string)GetValue(KeyProperty); }
            set { SetValue(KeyProperty, value); }
        }
        public string Input
        {
            get { return (string)GetValue(InputProperty); }
            set { SetValue(InputProperty, value); }
        }

        //private string key;
        //public string Key
        //{
        //    get { return key; }
        //    set { key = value; }
        //}

        //private string s;
        //public string Input
        //{
        //    get { return s; }
        //    set { s = value; }
        //} 
        public override ActivityExecutionStatus Run(BookmarkManager mgr)
        {
            //没有做特殊处理，key肯定是null.
            if (string.IsNullOrEmpty(Key))
            {
                Console.WriteLine("Key your enterred is empty.");
                return ActivityExecutionStatus.Closed;
            }

            // Print the greeting if the key is provided
            if (Key.Equals(Input ))
                Console.WriteLine("Key is correct!");
            else
            {
                Console.WriteLine("Wrong key!");
            }

            mgr.Done(false);
            return ActivityExecutionStatus.Closed;
        }
    }
     
}
